package com.pangsir.bookstore.dao.impl;

import com.pangsir.bookstore.dao.CartItemDao;
import com.pangsir.bookstore.pojo.CartItem;
import com.pangsir.bookstore.pojo.User;
import com.pangsir.myssm.basedao.BaseDAO;

import java.util.List;

public class CartItemDaoImpl extends BaseDAO<CartItem> implements CartItemDao {
    @Override
    public List<CartItem> getCartItemListByUser(User user) {
        String sql = "select * from t_cart_item where userBean = ?";
        return executeQuery(sql,user.getId());
    }

    @Override
    public void addCartItem(CartItem cartItem) {
        String sql = "insert into t_cart_item value(0,?,?,?)";
        super.executeUpdate(sql,
                cartItem.getBook().getId(),
                1,
                cartItem.getUserBean().getId());
    }

    @Override
    public void updateCartItem(CartItem cartItem, Integer buyCount) {
        String sql = "update t_cart_item set buyCount = ? where id = ?";
        super.executeUpdate(sql,buyCount,cartItem.getId());

    }

    @Override
    public void deleteCartItem(CartItem cartItem) {
        String sql = "delete from t_cart_item where id = ?";
        super.executeUpdate(sql,cartItem.getId());
    }
}
